#include <stdio.h>
#include <stdint.h>
#include <string.h>

#include "bits-set/bits.h"
#include "idea.h"
#include "io.h"


static void encrypt(bit_array *initial_keys, uint16_t *data)
{
    uint16_t subkeys[IDEA_SUBKEYS] = {0};
    generate_subkeys(initial_keys, subkeys);
    rounds(subkeys, data);
}


/*
static void decrypt(uint16_t *subkeys, bit *data)
{
    // TODO
}
*/


static void startup_messages(void)
{
    printf("Complied: %s %s\n", __DATE__, __TIME__);
}


int main(void)
{
    startup_messages();

    bit_array initial_keys[IDEA_INITIAL_KEYS * 16] = {0};
    input_hex_to_bits(initial_keys, IDEA_INITIAL_KEYS);

    uint16_t data[IDEA_DATA_BLOCK] = {0};
    input_hex_to_int16(data, IDEA_DATA_BLOCK);

    putchar('\n');
    printf("Input Data:\n");
    print_uint16_array(data, 4, " ");

    encrypt(initial_keys, data);
    printf("Output Data:\n");
    print_uint16_array(data, 4, " ");

    memset(initial_keys, 0, IDEA_INITIAL_KEYS);
    memset(data, 0, IDEA_DATA_BLOCK);

    return 0;
}
